﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace SquareChaseBot
{
    class Program
    {
        /// <summary>
        /// Main program entry point.
        /// </summary>
        /// <param name="args">
        /// Program arguments.
        /// </param>
        static void Main(string[] args)
        {
            PrintProgramInformation();

            ShowMenu();
        }

        /// <summary>
        /// Starts the bot playing the game. When the bot has finished, the
        /// user is shown the main menu again.
        /// </summary>
        static void PlayGame()
        {
            BotPlayer bot = new BotPlayer();
            bot.Play(10);

            ShowMenu();
        }

        /// <summary>
        /// Prints program information.
        /// </summary>
        static void PrintProgramInformation()
        {
            Console.WriteLine("Square Chase Bot");
            Console.WriteLine("(c) Copyright Chris Watson 2012");
            Console.WriteLine();
        }

        /// <summary>
        /// Shows the main program menu. On selection, executes chosen action.
        /// </summary>
        static void ShowMenu()
        {
            Console.WriteLine("p Play game");
            Console.WriteLine("e Exit");

            bool validResponse;

            do
            {
                Console.Write("Choose: ");

                string userChoice = Console.ReadLine();

                switch (userChoice.ToUpper())
                {
                    case "P":
                        PlayGame();
                        validResponse = true;
                        break;

                    case "E":
                        // Program will exit after leaving this method.
                        validResponse = true;
                        break;

                    default:
                        validResponse = false;
                        break;
                }

                if (!validResponse)
                {
                    Console.WriteLine(
                        "'{0}' is not a valid response. Please try again.",
                        userChoice);
                }

            } while (!validResponse);
        }
    }
}
